<HTML><HEAD><TITLE>bytes_to_term(+String, -Term)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Term Manipulation</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>bytes_to_term(+String, -Term)</H1>
Converts String, which is supposed to be an encoding of a term, into Term.


<DL>
<DT><EM>String</EM></DT>
<DD>A string produced by term_to_bytes/2.
</DD>
<DT><EM>Term</EM></DT>
<DD>A variable.
</DD>
</DL>
<H2>Description</H2>
   This predicate decodes strings produced by term_to_bytes/2 and
   reconstructs the encoded term.  The string representation is
   machine-independent, can be stored in files, sent over networks etc.
   Note however that the string can contain arbitrary bytes,
   including NUL and control characters.

<P>
   The predicate attempts to reconstruct the term with all its attached
   variable attributes and delayed goals. For this to be possible, the
   variable attributes and the predicates corresponding to delayed goals
   must all be defined in the environment where the term is reconstructed.

<P>
   The term_to_bytes/bytes_to_term predicates differ from term_string/2
   in that they do not create a human-readable representation, but are
   significantly faster and convert the term with all its attributes.

<P>

<H3>Modes and Determinism</H3><UL>
<LI>bytes_to_term(+, -) is det
</UL>
<H3>Modules</H3>
This predicate is sensitive to its module context (tool predicate, see @/2).
<H3>Exceptions</H3>
<DL>
<DT><EM>(5) type error </EM>
<DD>String is not a string.
</DL>
<H2>Examples</H2>
<PRE>
[eclipse]: term_to_bytes(s(X),String), bytes_to_term(String, Term).
String = "\000\000\000\b\001\002\013\001\001s\000\377\006\376\006\001X\000"
Term = s(X)
yes.



</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/termmanip/term_to_bytes-2.html">term_to_bytes / 2</A>, <A HREF="../../kernel/termmanip/copy_term-2.html">copy_term / 2</A>, <A HREF="../../kernel/termmanip/copy_term-3.html">copy_term / 3</A>, <A HREF="../../kernel/ioterm/writeq-1.html">writeq / 1</A>, <A HREF="../../kernel/ioterm/writeq-2.html">writeq / 2</A>, <A HREF="../../kernel/ioterm/write_canonical-1.html">write_canonical / 1</A>, <A HREF="../../kernel/ioterm/write_canonical-2.html">write_canonical / 2</A>
</BODY></HTML>
